package com.ad.pet.app.account.order.fragment;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.User;
import com.ad.pet.models.remote.account.order.BigOrder;
import com.ad.pet.models.remote.account.order.OrderType;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by SEELE on 2019/2/13.
 */
public class OrderStatusPresenter extends AbsBasePresenter implements OrderStatusContract.Presenter{

    private ApiService mApiService;
    private OrderStatusContract.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;

    @Inject
    public OrderStatusPresenter(ApiService apiService,
                            Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }
    @Override
    public void onCreate(OrderStatusContract.View view) {
            this.mView = view;
    }


    @Override
    public void getPacketInfo(String order_id) {
        mRxDisposable.add(mApiService.order_packet_lists(order_id).subscribe(new AppSubscriber<BigOrder>(mView) {
            @Override
            public void next(BigOrder listCommList) {
                mView.getPacketInfoSuccess(listCommList);
            }
        }));
    }

    @Override
    public void getGoodOrderDetail(String order_id) {
        mRxDisposable.add(mApiService.getGoodOrderDetail(order_id).subscribe(new AppSubscriber<BigOrder>(mView) {
            @Override
            public void next(BigOrder listCommList) {
                mView.getGoodOrderDetailSuccess(listCommList);
            }
        }));
    }

    @Override
    public void getOrderStatus(String status,String page) {
        mRxDisposable.add(mApiService.order_lists(status,page).subscribe(new AppSubscriber<List<BigOrder>>(mView) {
            @Override
            public void next(List<BigOrder> orderStatuses) {
                mView.getOrderStatusSuccess(orderStatuses);
            }
        }));
    }

    @Override
    public void getPending(String status,String page) {
        mRxDisposable.add(mApiService.order_unpaid(status,page).subscribe(new AppSubscriber<List<BigOrder>>(mView) {
            @Override
            public void next(List<BigOrder> orderStatuses) {
                mView.getPendingSuccess(orderStatuses);
            }
        }));
    }

    @Override
    public void cancelOrder(String order_id) {
        mRxDisposable.add(mApiService.cancel_order(order_id).subscribe(new AppSubscriber<User>(mView) {
            @Override
            public void next(User resultBean) {
                mView.cancelOrderSuccess();
            }
        }));
    }

    @Override
    public void confirmRecive(String order_id) {
        mRxDisposable.add(mApiService.confir_order(order_id).subscribe(new AppSubscriber<User>(mView) {
            @Override
            public void next(User resultBean) {
                mView.confirmOrderSuccess();
            }
        }));
    }

    @Override
    public void myAppointList(String status,String page) {
        mRxDisposable.add(mApiService.appoint_list(status,page).subscribe(new AppSubscriber<List<OrderType>>(mView) {
            @Override
            public void next(List<OrderType> orderStatuses) {
                mView.myAppointListSuccess(orderStatuses);
            }
        }));
    }

    @Override
    public void cancelAppointList(String order_id) {
        mRxDisposable.add(mApiService.cancel_appoint(order_id).subscribe(new AppSubscriber<User>(mView) {
            @Override
            public void next(User resultBean) {
                mView.confirmOrderSuccess();
            }
        }));
    }


    @Override
    public void onDestroy() {
        if (mRxDisposable != null)
            mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }
}
